package controller;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThenApplyDemo {

    final ExecutorService executorService = Executors.newFixedThreadPool(100);

    final CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {

        try {
            TimeUnit.SECONDS.sleep(3);
            System.out.println(111);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        return 123;
    }, executorService).handleAsync((v,throwable)->{

        int rel =1;
        if (throwable==null){
            rel =v*10;
        }else {
            System.out.println(throwable.getMessage());
        }

        return  rel;
    },executorService);




    /* 用这个是不能出异常的时候捕捉到异常信息的
    .thenApply(v->{

        int re=v*10;
        return  re;
    });*/
}
